//
//  GetGoodsViewController.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/20.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class GetGoodsViewController: UITableViewController,GetGoodsCellDelegate {
    
    //表格数据源
    lazy var dataArr : NSMutableArray = {
        var data = NSMutableArray()
        data = ["收货人","手机号","省份","城市","地区","详细地址"]
        return data
    }()
    
    //提示标题数据源
    lazy var aletDesc : NSMutableArray = {
        var data = NSMutableArray()
        data = ["请输入您的姓名","请输入您的手机号","请选择省份","请选择城市","请选择地区","请输入您的详细地址"]
        return data
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置标题
        self.navigationItem.title = "我的收货地址"
        
        //设置样式
        setStyle()
    }

}

//表格代理方法
extension GetGoodsViewController {
    // MARK: - Table view data source
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 2
    }
    
    //设置section间距
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 1
    }
    
    //数据源
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        switch section {
        case 0:
            return dataArr.count
        default:
            return 1
        }
        
        
    }
    
    //单机方法
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("单机了",indexPath.row)
    }
    
    //设置行高
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        
        if indexPath.section == 0 && indexPath.row == 5 {
            return 100
        } else {
            return 45
        }
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellID") as? GetGoodsCell
        if cell == nil {
            //取出分割线
            tableView.separatorStyle = UITableViewCellSeparatorStyle.none
            
            cell = GetGoodsCell(style: .default, reuseIdentifier: "cellID")
            
            //监听代理
            cell?.delegate = self
        }
        
        
        
        //赋值前置标题
        cell?.labelDesc.text = dataArr[indexPath.row] as? String
        //提示标题赋值
        cell?.nameLabel.plStrSize(str: (aletDesc[indexPath.row] as? String)!, holderColor: UIColor.gray, textFontSize: 13)
        
        //控制第二组按钮的显示
        if indexPath.section == 1 {
            cell?.btn.isHidden = false
            cell?.nameLabel.isHidden = true
            cell?.backgroundColor = UIColor.clear
            cell?.labelDesc.isHidden = true

        } else {
            cell?.btn.isHidden = true
            cell?.labelDesc.isHidden = false
        }
        
        //控制倒三角的显示
        if indexPath.section == 0 && indexPath.row == 2 || indexPath.row == 3 || indexPath.row == 4  {
            cell?.disclosureImg.isHidden = false
        } else {
            cell?.disclosureImg.isHidden = true
        }
        
        //控制分割线的显示
        switch indexPath.section {
        case 0:
            cell?.line.isHidden = false
        default:
            cell?.line.isHidden = true
        }
        
        //控制详细地址所在行的显示
        if indexPath.section == 0 && indexPath.row == 5 {
            cell?.detailTextView.isHidden = false
            cell?.line.isHidden = true
        } else {
            cell?.detailTextView.isHidden = true
        }
        
        
        return cell!
    }
    
    
}


// MARK:- 设置表格样式
extension GetGoodsViewController {
    fileprivate func setStyle() -> Void {
        
        tableView = UITableView(frame: self.view.bounds, style: .grouped)
    }
}


// MARK:- 监听代理方法
extension GetGoodsViewController {
    func savePersonInfoSEL() {
        print("收到保存信息方法")
        
        self.navigationController!.popToRootViewController(animated: true)
    }
}
